package com.lenovo.lcdm.dcm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lenovo.lcdm.common.model.ResponseVo;
import com.lenovo.lcdm.dcm.dto.DcmConfigurationQueryDto;
import com.lenovo.lcdm.dcm.entity.DcmConfiguration;
import com.lenovo.lcdm.dcm.entity.DcmBusinessConfigurationCategoryC;
import com.lenovo.lcdm.dcm.entity.DcmBusinessConfigurationKeywords;
import com.lenovo.lcdm.dcm.service.DcmConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


/**
 * @Auther xujing30
 * @Date 2024/01/19
 * @Description
 */
@RestController
public class DcmConfigurationController {

    @Autowired
    private DcmConfigurationService configurationService;

    @PostMapping("/upload/configuration/{type}")
    public ResponseVo<Long> uploadConfiguration(@RequestParam(value = "file") MultipartFile file, @PathVariable String type) throws IOException {
        ResponseVo<Long> responseVo = new ResponseVo();
        Long newVersionId = configurationService.uploadConfiguration(file, type);
        responseVo.setData(newVersionId);
        return responseVo;
    }

    @PostMapping("/configuration/list")
    @ResponseBody
    public ResponseVo<Page<DcmConfiguration>> getConfigurationList(@RequestParam int pageNo, @RequestParam int pageSize, @RequestBody DcmConfigurationQueryDto queryDto) throws IOException {
        ResponseVo<Page<DcmConfiguration>> responseVo = new ResponseVo();
        Page page = new Page(pageNo, pageSize);
        List<DcmConfiguration> data = configurationService.getConfigurations(page, queryDto);
        page.setRecords(data);
        responseVo.setData(page);
        return responseVo;
    }

    @GetMapping("/configuration/{id}")
    @ResponseBody
    public ResponseVo<DcmConfiguration> getConfigurationDetail(@PathVariable Long id) throws IOException {
        ResponseVo<DcmConfiguration> responseVo = new ResponseVo();
        DcmConfiguration data = configurationService.getDetail(id);
        responseVo.setData(data);
        return responseVo;
    }

    @GetMapping("/configuration/{id}/history")
    @ResponseBody
    public ResponseVo<List<DcmConfiguration>> getConfigurationHistory(@PathVariable Long id){
        ResponseVo<List<DcmConfiguration>> responseVo = new ResponseVo();
        List<DcmConfiguration> data = configurationService.getHistory(id);
        responseVo.setData(data);
        return responseVo;
    }

    @GetMapping("/Keywords/configuration")
    @ResponseBody
    public ResponseVo<List<DcmBusinessConfigurationKeywords>> getKeywords(){
        ResponseVo<List<DcmBusinessConfigurationKeywords>> responseVo = new ResponseVo();
        List<DcmBusinessConfigurationKeywords> data = configurationService.getKeywords();
        responseVo.setData(data);
        return responseVo;
    }

    @GetMapping("/category/c/configuration")
    @ResponseBody
    public ResponseVo<List<DcmBusinessConfigurationCategoryC>> getCategory(){
        ResponseVo<List<DcmBusinessConfigurationCategoryC>> responseVo = new ResponseVo();
        List<DcmBusinessConfigurationCategoryC> data = configurationService.getCategoryC();
        responseVo.setData(data);
        return responseVo;
    }
}
